import polars as pl
from scipy.stats import ttest_ind, levene

df = pl.read_csv("B Chapter 07/data.csv")

pass_check = lambda p: p >= 0.05

print("Homogeneity test of variance: F test")

x1 = df.filter(pl.col("group") == 1).select("value")
x2 = df.filter(pl.col("group") == 2).select("value")

stats, p_value = levene(x1, x2)
passed = pass_check(p_value)

print(f"F test: F={stats}, {p_value=}, {passed=}")

print("Independent t test")

stats, p_value = ttest_ind(x1, x2)
passed = pass_check(p_value)

print(f"Independent t test: t={stats}, {p_value=}, {passed=}")
